import { Card } from "../game/gameModel";
import { CardColor } from "./defineConfig";

function getMasterCards(cards: Card[], masterColor: CardColor): Card[] {
    let cs: Card[] = [];
    cards.forEach(card => {
        if (card.isMaster(masterColor)) cs.push(card);
    })
    return cs;
}

function getColorCards(cards: Card[], masterColor: CardColor, color: CardColor): Card[] {
    let cs: Card[] = [];
    cards.forEach(card => {
        if (!card.isMaster(masterColor) && card.color == color)
                cs.push(card);
    })
    return cs;
}

// 获取合适(能出的)的牌
function getSuitableCards(cards: Card[], masterColor: CardColor, firstCard: Card): Card[] {
    if (firstCard.isMaster(masterColor)) {
       let suitableCards = getMasterCards(cards, masterColor);
       return (suitableCards.length === 0) ? cards : suitableCards;
    }

    let suitableCards = getColorCards(cards, masterColor, firstCard.color);
    return (suitableCards.length === 0) ? cards : suitableCards;
}

export {
    getMasterCards,
    getColorCards,
    getSuitableCards
}
